/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package phoside.io.fasta.parser;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author gjj
 */
public abstract class AbstractStringParser implements StringParser {
    protected Map<String,Object> map; //map field name to field value

    public AbstractStringParser() {
        map = new HashMap();
    }

    public abstract void parse(String str);

    public Object getField(String fieldName) {
        if (fieldName==null) {
            throw new NullPointerException("Null fieldName.");
        }

        return map.get(fieldName);
    }

    protected Object addField(String fieldName, Object obj) {
        if (fieldName==null || obj==null) {
            throw new NullPointerException("");
        }
        return map.put(fieldName, obj);
    }

    protected Object removeField(String fieldName) {
        if (fieldName==null) {
            throw new NullPointerException("");
        }
        return map.remove(fieldName);
    }

    protected Set<String> allFields() {
        return map.keySet();
    }
}
